package displayboardinfo.tests;

import java.net.URI;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import javax.xml.bind.JAXBException;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;

import displayboardinfo.entities.Patient;
import displayboardinfo.messages.ListPatientsRes;

public class GetPatientsTest {
	public static void main(String[] args) throws JAXBException {
		ClientConfig config = new DefaultClientConfig();
		Client client = Client.create(config);
		WebResource service = client.resource(getBaseURI());
		// Fluent interfaces
//		System.out.println(service.path("rest").path("hello").accept(
//				MediaType.TEXT_PLAIN).get(ClientResponse.class).toString());
		// Get plain text
//		System.out.println(service.path("rest").path("hello").accept(
//				MediaType.TEXT_PLAIN).get(String.class));
		// Get XML
		
		ClientResponse res = service.path("patients").path("list").accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
		
		if (res == null){
			System.out.println("null");
			return;
		}
		
		System.out.println(res);
		
		ListPatientsRes patients = res.getEntity(ListPatientsRes.class);
		
		for (Patient pat : patients.getPatients())
			System.out.println(pat);

	}

	private static URI getBaseURI() {
		return UriBuilder.fromUri(
				"http://localhost:8080/DisplayBoardInfoServer").build();
	}

}
